// router.js
import { createRouter, createWebHistory,createWebHashHistory } from 'vue-router';

// 引入组件(懒加载)
const HomePage = () => import('../pages/index/index.vue')
const result = () => import('../pages/result/index.vue')
const avoidRisk = () => import('../pages/avoid-risk/index.vue')
const listIndex = () => import('../pages/list/index.vue')
const menus = () => import('../pages/menus/menus.vue')
// const collapse = () => import('../pages/menus/collapse.vue')
const chartDemos = () => import('../pages/menus/chartDemos.vue')
const notFound = () => import('../pages/not-found/404.vue')
// const pullList = () => import('../pages/menus/pullList.vue')
// const PullRefresh = () => import('../pages/menus/PullRefresh.vue')
//

// 定义路由
export const routes = [
    { path: '/', component: HomePage ,meta: {title:"个股扫雷首页"}},
    { path: '/index', component: HomePage,meta: {title:"个股扫雷首页" }},
    { path: '/result', component: result,meta: {title:"结果页" }},
    { path: '/avoid-risk', component: avoidRisk,meta: {title:"历史避险表现页面" }},
    // { path: '/collapse', component: collapse,meta: {title:"折叠面板" }},
    { path: '/chartDemos', component: chartDemos,meta: {title:"图表配置demo" }},
    { path: '/menus', component: menus,meta:{title:"导航" }},
    { path: '/list', component: listIndex,meta:{title:"列表" }},
    { path: '/404', component: notFound ,meta: {title:"404"}},
    // { path: '/pullList', component: pullList ,meta: {title:"上拉和加载更多"}},
    // { path: '/PullRefresh', component: PullRefresh ,meta: {title:"刷新DEMO"}},
    {
        path: "/:catchAll(.*)",
        redirect: '/404',
    },
];

// 创建router实例
const router = createRouter({
    history: createWebHistory(),
    // history: createWebHashHistory(),
    routes,
});
router.beforeEach((to,from,next)=>{
    document.body.scrollTop = 0
    document.documentElement.scrollTop = 0
    document.title = to?.meta?.title;
    next()
})

export default router;